package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ClientBean;
import com.project.service.IClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 客户Controller
 */
@RequestMapping("client")
@RestController
public class ClientController {

    @Autowired
    private IClientService clientService;

    //动态条件分页查询客户信息
    @RequestMapping("findByItem")
    public IPage<ClientBean> findByItem(Integer pageNO, String name, String ranges){
        return clientService.findByItem(pageNO, name, ranges);
    }

    //根据客户id查询客户信息
    @RequestMapping("findById")
    public ClientBean findById(Integer clientId){
        return clientService.findById(clientId);
    }

    //根据客户名称查询客户
    @RequestMapping("findByName")
    public ClientBean findByName(String name){
        return clientService.findByName(name);
    }

    //添加客户
    @RequestMapping("addClient")
    public String addClient(ClientBean client){
        clientService.addClient(client);
        return "ok";
    }

    //根据客户id修改负责人名称和电话、经营范围
    @RequestMapping("updateClient")
    public String updateClient(Integer clientId, String headerName, String headerPhone, String ranges){
        clientService.updateClient(clientId, headerName, headerPhone, ranges);
        return "ok";
    }

    //查询所有客户
    @RequestMapping("findAll")
    public List<ClientBean> findAll(){
        return clientService.findAll();
    }
}
